//package demo5;
//
//
///**
// * Created with IntelliJ IDEA.
// * Description:
// * User: 石方旭
// * Date: 2022-08-12
// * Time: 8:56
// */
//public class TestDemo {
//    // 给定一棵二叉树的头节点head，返回这颗二叉树中最大的二叉搜索子树的大小
//    static class TreeNode{
//        public int val;
//        public TreeNode left;
//        public TreeNode right;
//
//        public TreeNode(int val){
//            this.val = val;
//        }
//    }
//    //X不做头---有答案
//    //这颗二叉树的最大值就是左树搜索二叉树的最大值和右树的最大值
//    //X做头----有答案
//    //这一整颗二叉树是答案
//    //满足 :1.左树是搜索二叉树
//    //2.右树也是
//    //3.答案就是左树节点+右树节点+1
//    //------------------------------------
//    //信息体
////    static class Info{
////        public int subBSTSize;//是否是搜索二叉树
////        public int max;//树的最大值
////        public int min;//树的最小值
////        public int size;//整颗二叉树的大小
////
////        public Info(int subBSTSize,int max,int min,int size){
////            this.subBSTSize = subBSTSize;
////            this.max = max;
////            this.min = min;
////            this.size = size;
////        }
////    }
////    public static Info process(TreeNode head) {
////         if(head==null) return null;
////         Info leftInfo = process(head.left);
////         Info rightInfo = process(head.right);
////         int max = head.val;//树的最大值
////         int min = head.val;//树的最小值
////         int size =1;//整颗二叉树的大小
////         if(leftInfo!=null){
////             max = Math.max(max, leftInfo.max);
////             min = Math.min(min,leftInfo.min);
////             size+= leftInfo.size;;
////         }
////         if(rightInfo!=null){
////             max = Math.max(max, rightInfo.max);
////             min = Math.min(min,rightInfo.min);
////             size+= rightInfo.size;;
////         }
////         int p1 = -1;
////         if(leftInfo!=null){
////             p1= leftInfo.subBSTSize;
////         }
////         int p2 = -1;
////         if(rightInfo!=null){
////             p2 = rightInfo.subBSTSize;
////         }
////         int p3 = -1;
////         boolean left = leftInfo == null ? true :leftInfo.size== leftInfo.subBSTSize;
////         boolean right = rightInfo==null ? true : rightInfo.size == rightInfo.size;
////         if(left&&right){
////             boolean L = leftInfo == null ? true : leftInfo.max < head.val;
////             boolean R = rightInfo==null ? true : rightInfo.min > head.val;
////             if(L&&R){
////                 p3 = leftInfo.size + rightInfo.size +1;
////             }
////         }
////        int subBSTSize = Math.max(p1,Math.max(p2,p3));
////
////         return new Info(subBSTSize,max,min,size);
////
////    }
//
//
////    public static Info process(TreeNode head){
////        if(head==null) return null;
////
////        Info leftInfo = process(head.left);
////        Info rightInfo = process(head.right);
////        int max = head.val;//树的最大值
////        int min = head.val;//树的最小值
////        int size = 1;//整颗二叉树的大小
////        if(leftInfo!=null){
////            max = Math.max(max,leftInfo.max);
////            min = Math.min(min,leftInfo.min);
////            size += leftInfo.size;
////        }
////        if(rightInfo!=null){
////            max = Math.max(max,rightInfo.max);
////            min = Math.min(min,rightInfo.min);
////            size += rightInfo.size;
////        }
////        int p1 = -1;
////        if(leftInfo!=null){
////            p1 = leftInfo.SubBSTSize;
////        }
////        int p2 = -1;
////        if(rightInfo!=null){
////            p2 = rightInfo.SubBSTSize;
////        }
////        int p3 = -1;
////        boolean leftBST = leftInfo==null ? true :(leftInfo.size== leftInfo.SubBSTSize);
////        boolean rightBST = rightInfo==null ? true :(rightInfo.size==rightInfo.SubBSTSize);
////
////        if(leftBST&&rightBST){
////            boolean L = leftInfo==null ? true :leftInfo.max<head.val ? true : false;
////            boolean R = rightInfo == null ? true :rightInfo.min > head.val ? true : false;
////            if(L&&R){
////                int leftSize = leftInfo==null ? 0 : leftInfo.size;
////                int rightSize = rightInfo==null ?0 : rightInfo.size;
////                p3 = leftSize + rightSize +1;
////            }
////        }
////
////        int SubBSTSize = Math.max(p1,Math.max(p2,p3));
////        return new Info(SubBSTSize,max,min,size);
////    }
//
//    public static int maxBinarySearchTreeSize(TreeNode head){
//        if(head==null) return 0;
//           return process(head).subBSTSize;
//    }
//
//
//}
